package com.itqf.service.impl;

import com.itqf.bean.DtsGoodsSpecification;
import com.itqf.bean.DtsGoodsSpecificationExample;
import com.itqf.mapper.DtsGoodsSpecificationMapper;
import com.itqf.service.DtsGoodsSpecificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * projectName: gp_manage
 *
 * @author: 赵伟风
 * time: 2021/8/23 23:23
 * description:
 */
@Service
public class DtsGoodsSpecificationServiceImpl implements DtsGoodsSpecificationService {

    @Autowired
    private DtsGoodsSpecificationMapper dtsGoodsSpecificationMapper;

    /**
     * 查询商品类别的的规格
     *
     * @param id
     * @return
     */
    @Override
    public List<DtsGoodsSpecification> findSpecificationByGid(Integer id) {

        DtsGoodsSpecificationExample example = new DtsGoodsSpecificationExample();

        DtsGoodsSpecificationExample.Criteria criteria = example.createCriteria();

        criteria.andDeletedEqualTo(false);

        criteria.andGoodsIdEqualTo(id);


        List<DtsGoodsSpecification> dtsGoodsSpecifications = dtsGoodsSpecificationMapper.selectByExample(example);

        return dtsGoodsSpecifications;
    }

    /**
     * 删除规格
     *
     * @param gid
     */
    @Override
    public void deleteByGid(Integer gid) {

        DtsGoodsSpecificationExample example = new DtsGoodsSpecificationExample();
        example.createCriteria().andGoodsIdEqualTo(gid);

        dtsGoodsSpecificationMapper.deleteByExample(example);
    }

    /**
     * 添加规格
     *
     * @param specification
     */
    @Override
    public void add(DtsGoodsSpecification specification) {

        dtsGoodsSpecificationMapper.insertSelective(specification);
    }
}
